// (Current time) Listing 2.7, ShowCurrentTime.java, gives a program that displays 
// the current time in GMT. Revise the program so that it prompts the user to enter 
// the time zone offset to GMT and displays the time in the specified time zone.
import java.util.Scanner;

public class test28 {
    public static void main(String[] args) {
        // 获取当前GMT时间的总毫秒数
        long totalMilliseconds = System.currentTimeMillis();
        
        // 计算总秒数
        long totalSeconds = totalMilliseconds / 1000;
        long currentSecond = totalSeconds % 60;
        
        // 计算总分钟数
        long totalMinutes = totalSeconds / 60;
        long currentMinute = totalMinutes % 60;
        
        // 计算总小时数
        long totalHours = totalMinutes / 60;
        long gmtHour = totalHours % 24;
        
        // 创建Scanner对象读取用户输入
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the time zone offset to GMT: ");
        int timeZoneOffset = input.nextInt();
        
        // 计算指定时区的小时
        long targetHour = gmtHour + timeZoneOffset;
        
        // 处理小时超出范围的情况（0-23）
        if (targetHour >= 24) {
            targetHour -= 24;
        } else if (targetHour < 0) {
            targetHour += 24;
        }
        
        // 显示结果
        System.out.println("The current time is " + targetHour + ":" 
            + currentMinute + ":" + currentSecond);
        
        // 关闭Scanner
        input.close();
    }
}
